<!-- 黑名单号码 -->
<template>
	<div id="BlackNum">
		<a-card :bordered="false">
			<a-form ref="searchFormRef" name="advanced_search" :model="searchFormState" class="ant-advanced-search-form">
				<a-row :gutter="24">
					<a-col :span="6">
						<a-form-item label="类型：" name="type">
							<a-select v-model:value="searchFormState.type" :options="typeOptions" placeholder="请选择类型" allow-clear />
						</a-form-item>
					</a-col>
					<a-col :span="6">
						<a-form-item label="手机号：" name="phone">
							<a-input v-model:value="searchFormState.phone" placeholder="请输入手机号" allow-clear />
						</a-form-item>
					</a-col>
					<a-col :span="6">
						<a-form-item label="日期范围" name="dateRange">
							<a-range-picker v-model:value="searchFormState.dateRange" valueFormat="YYYY-MM-DD" :allowClear="false" />
						</a-form-item>
					</a-col>
					<a-col :span="6">
						<a-button type="primary" @click="tableRef.refresh(true)">查询</a-button>
						<a-button style="margin: 0 8px" @click="reset">重置</a-button>
					</a-col>
				</a-row>
			</a-form>
		</a-card>
		<a-card :bordered="false" class="mt-2">
			<s-table ref="tableRef" :columns="columns" :data="loadData" bordered :tool-config="toolConfig">
				<template #operator>
					<a-space>
						<a-button type="primary" @click="formRef.onOpen()" style="margin-right: 10%">
							<template #icon>
								<plus-outlined />
							</template>
							新增
						</a-button>
						<a-button type="primary" @click="upload.openUpload()">
							<template #icon>
								<import-outlined />
							</template>
							导入
						</a-button>
					</a-space>
				</template>
				<template #bodyCell="{ column, record }">
					<template v-if="column.dataIndex === 'action'">
						<a-popconfirm title="确定要删除此手机号吗？" @confirm="deleteNum(record.id)">
							<a-button type="link" danger size="small">删除</a-button>
						</a-popconfirm>
					</template>
				</template>
			</s-table>
		</a-card>
		<Form ref="formRef" @successful="tableRef.refresh(true)" />
		<Upload ref="upload" @successful="tableRef.refresh(true)" />
	</div>
</template>
<script setup name="BlackNum">
	import Form from '@/views/tjzy/abnormalNum/black/form.vue'
	import abnormalBlackApi from '@/api/tjzy/abnormal/black/abnormalBlackApi'
	import Upload from '@/views/tjzy/abnormalNum/black/upload.vue'
	import dayjs from 'dayjs'

	// ===========================================DATA======================================================
	const upload = ref()
	const searchFormState = ref({
		type: undefined,// 类型 1-线路 2-业务 3-停机空号
		phone: undefined,
		dateRange: [
			dayjs().subtract(6, 'day').format('YYYY-MM-DD'), // 今天减去7天
			dayjs().format('YYYY-MM-DD') // 今天的日期
		]
	})
	let typeOptions = ref([
		{
			label: '线路',
			value: 1
		},
		{
			label: '业务',
			value: 2
		}
	])
	const searchFormRef = ref()
	const tableRef = ref()
	const formRef = ref()
	const toolConfig = { refresh: true, height: true, columnSetting: false, striped: false }
	const columns = [
		{
			title: '手机号',
			dataIndex: 'phone'
		},
		{
			title: '类型',
			dataIndex: 'type',
			customRender: (param) => {
				const find = typemap.find((item) => item.value == param.text)
				return find ? find.label : ''
			}
		},
		{
			title: '日期',
			dataIndex: 'belongingMonth'
		},
		{
			title: '操作',
			dataIndex: 'action',
			width: 80
		}
	]
	const typemap = [
		{
			value: 1,
			label: '线路'
		},
		{
			value: 2,
			label: '业务'
		},
		{
			value: 3,
			label: '停机空号'
		}
	]
	// ===========================================LIFECYCLE HOOKS===========================================
	// ===========================================METHODS==================================================
	const reset = () => {
		searchFormRef.value.resetFields()
		tableRef.value.refresh(true)
	}
	// ===========================================REQUEST==================================================
	const loadData = (parameter) => {
		const data = {
			searchType: 1, // 数据库区分模块 1-黑名单 2-停机空号
			phone: searchFormState.value.phone,
			beginTime: `${searchFormState.value.dateRange[0]} 00:00:00`,
			endTime: `${searchFormState.value.dateRange[1]} 23:59:59`,
			type: searchFormState.value.type,
			current: parameter.current,
			size: parameter.size
		}
		return abnormalBlackApi.pageList(data).then((res) => {
			return res
		})
	}
	// 删除
	const deleteNum = (id) => {
		abnormalBlackApi.delete(id).then(() => {
			tableRef.value.refresh(true)
		})
	}
</script>
<style lang="less" scoped></style>
